<?php
namespace Home\Controller;
use Think\Controller;
class InterfaceAppToolController extends Controller {
    public function typelist(){//类型列表
        $versionCode=$_REQUEST['versionCode'];
        $Arr=array(
            array('kind'=>2,'name'=>'八字排盘'), array('kind'=>1,'name'=>'紫微排盘'), array('kind'=>3,'name'=>'六爻排盘'), array('kind'=>4,'name'=>'七政四余'),array('kind'=>5,'name'=>'奇门遁甲'),array('kind'=>7,'name'=>'六壬排盘'),
        );
        if($versionCode>=160){
            array_push($Arr,array('kind'=>8,'name'=>'铁板神数'));
        }
        $result=array('code'=>1,'content'=>$Arr,'tip'=>"success");
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }
    public function kindList($type=null){//分类
        $Arr=array(
            array('kind'=>1,'name'=>'家人'), array('kind'=>2,'name'=>'朋友'),
            array('kind'=>3,'name'=>'同学'), array('kind'=>4,'name'=>'同事'),
            array('kind'=>5,'name'=>'客户'), array('kind'=>6,'name'=>'名人'),
            array('kind'=>7,'name'=>'其他'),
        );
        if($type==1){//自身回调
            return $Arr;
        }
        $ArrData=array('code'=>1, 'content'=>$Arr, 'tip'=>"success");
        echo json_encode($ArrData,JSON_UNESCAPED_UNICODE);
    }
    public function addUser(){//添加用户
        $uid=$_REQUEST['uid'];
        $username=I('request.username');
        $birthday=I('request.birthday');
        $sex=$_REQUEST['sex'];
        $addr=$_REQUEST['addr'];
        $remarks=$_REQUEST['remarks'];
        $longitude=$_REQUEST['longitude'];//经度
        $userData=$_REQUEST['user'];
        $del=$_REQUEST['del'];//1保存 2不保存
        $type=$_REQUEST['type'];//1紫微命盘  2八字命盘  3六爻  4七政四余 5奇门遁甲 7大六壬 8铁板神数
        $typeName=$_REQUEST['typeName'];
        $lnYmd=$_REQUEST['lnymd'];//流年日期
        $noOrder=$_REQUEST['noOrder'];
        $kind=$_REQUEST['kind'];
        $information=$_REQUEST['information'];
        $sid=$_REQUEST['sid'];
        if($sid){//执行修改操作
            $this->addUpdateUser($sid,$information,$kind,$lnYmd,$longitude,$remarks,$addr,$sex,$birthday,$username);
        }

        judgeData(array($uid,$username),$_REQUEST);
        if(empty($del)){$del=2;}
        if(empty($type)){$type=0;}
        if(empty($kind)){$kind=7;}

        $userArr=M()->query("select sid from data_app_tool_user where uid='{$uid}' and username='{$username}' and birthday='{$birthday}' and sex='{$sex}' and kind='{$kind}' and addr='{$addr}' and information='{$information}' and remarks='{$remarks}' and lnymd='{$lnYmd}' order by sid desc");
        if($userArr[0]['sid']){
            $sid=$userArr[0]['sid'];
        }else{
            M()->query("insert into data_app_tool_user (uid,username,birthday,sex,addr,remarks,longitude,userData,del,type,typeName,lnYmd,kind,information)values('{$uid}','{$username}','{$birthday}','{$sex}','{$addr}','{$remarks}','{$longitude}','{$userData}','{$del}','{$type}','{$typeName}','{$lnYmd}','{$kind}','{$information}')");
            $sid=mysql_insert_id();
        }

        if($sid){
            $arr=array('code'=>1,'sid'=>$sid);
        }else{
            $arr=array('code'=>0);
        }
        echo json_encode($arr);
        if($noOrder==1){
        }elseif($type<=4){
            $this->orderPay($sid,$type,$uid,1,2);
        }
    }
    public function deleteUser(){//删除用户
        $sid=$_REQUEST['sid'];
        $type=$_REQUEST['type'];
        judgeData(array($sid),$_REQUEST);
        if($type==3){
            M()->query("delete from data_app_tool_lypp where sid='{$sid}'");
            M()->query("delete from data_app_tool_order where sid='{$sid}' and type='{$type}'");
        }else{
            M()->query("delete from data_app_tool_order where sid='{$sid}'");
            M()->query("delete from data_app_tool_user where sid='{$sid}'");
        }
        $arr=array('code'=>1,);
        echo json_encode($arr);
    }
    public function updateUser(){//修改用户
        $sid=$_REQUEST['sid'];
        $username=I('request.username');
        $birthday=I('request.birthday');
        $sex=$_REQUEST['sex'];
        $information=I('request.information');
        judgeData(array($username,$birthday,$sid),$_REQUEST);
        S('mingpan'.$sid,null);
        $updateStr="username='{$username}',birthday='{$birthday}'";
        if($sex||$sex==='0'){$updateStr.=",sex='{$sex}'";}
        if($information){
            $updateStr.=",information='{$information}'";
        }

        M()->query("update data_app_tool_user set {$updateStr} where sid='{$sid}'");
        $arr=array('code'=>1,);
        echo json_encode($arr);
    }
    public function addUpdateUser($sid,$information,$kind,$lnYmd,$longitude,$remarks,$addr,$sex,$birthday,$username){//新添加更新接口
        $updateStr="username='{$username}',birthday='{$birthday}'";
        if($sex||$sex==='0'){$updateStr.=",sex='{$sex}'";}
        if($information){$updateStr.=",information='{$information}'";}
        if($kind){$updateStr.=",kind='{$kind}'";}
        if($lnYmd){$updateStr.=",lnYmd='{$lnYmd}'";}
        if($longitude){$updateStr.=",longitude='{$longitude}'";}
        if($remarks){$updateStr.=",remarks='{$remarks}'";}
        if($addr){$updateStr.=",addr='{$addr}'";}
        M()->query("update data_app_tool_user set {$updateStr} where sid='{$sid}'");
        $arr=array('code'=>1,'sid'=>$sid);
        echo json_encode($arr);exit;
    }
    public function userData(){//查询用户数据列表
        $uid=$_REQUEST['uid'];
        $kind=$_REQUEST['kind'];
        $type=$_REQUEST['type'];
        judgeData(array($uid),$_REQUEST);
        if(empty($kind)){
            $kind=7;
        }
        if($type)$typeText="and type={$type}";
        if($type){
            $arr=M()->query("select sid,username,birthday,sex,createtime,addr,information,kind,remarks,type from data_app_tool_user where uid='{$uid}' and del<2 and kind='{$kind}' {$typeText} order by sid desc limit 20");
        }else{
            $arr=M()->query("select sid,username,birthday,sex,createtime,addr,information,kind,remarks,type from data_app_tool_user where uid='{$uid}' and del<2 and kind='{$kind}' and type>=0 and type<=4 and type!=3 order by sid desc limit 20");
        }


        foreach($arr as $key=>$value){
            $ymdArr=explode('-',$value['birthday']);
            $y=$ymdArr[1];
            $m=$ymdArr[2];
            $d=$ymdArr[3];
            $zyinli=yinli($y,$m,$d);
            $arr[$key]['yangli']=$y.'年'.$m.'月'.$d.'日';//阳历
            $arr[$key]['yinli']=$zyinli[0].'年'.$zyinli[1].$zyinli[2];//阴历
            //$arr[$key]['shengxiao']=$zyinli[6];
            if($value['type']==5){
                $arrRemarks=json_decode($value['remarks'],true);
                $username='';
                if($arrRemarks['qijuType']==1){$username.='四柱起局';}else{$username.='公历起局';}
                if($arrRemarks['qimen']==1){$username.='-飞盘奇门';}else{$username.='-转盘奇门';}
                if($arrRemarks['runfa']==1){$username.='-拆补无闰法';}else{$username.='-超接置闰法';}
                $arr[$key]['username']=$username;
            }elseif($value['type']==8){
                $arrRemarks=json_decode($value['remarks'],true);
                if($arrRemarks['tbType']==1){$typeName="八卦加则法";
                }elseif($arrRemarks['tbType']==2){$typeName="元会运世法";
                }elseif($arrRemarks['tbType']==3){$typeName="流年大运法";
                }
                $arr[$key]['typeName']=$typeName;
                $arr[$key]['url']="http://web.ddznzj.com/lingqiyixue/tbss/#/pages/tbss/result?sid={$value['sid']}";
            }
        }
        if(empty($arr[0])){
            $code=0;
        }else{
            $code=1;
        }
        $arr=array('code'=>$code,'content'=>$arr);
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function userBrithday(){//用户生日
        $uid=$_REQUEST['uid'];
        judgeData(array($uid),$_REQUEST);
        $arr=M()->query("select sid,username,birthday,kind from data_app_tool_user where uid='{$uid}' and del<2 and kind<=5 order by sid desc limit 20");

        $kindListArr=$this->kindList(1);
        foreach($arr as $key=>$value){
            $ymdArr=explode('-',$value['birthday']);
            $y=$ymdArr[1];$m=$ymdArr[2];$d=$ymdArr[3];$hour=$ymdArr[4];
            $zyinli=yinli($y,$m,$d);
            $arr[$key]['yangli']=$y.'年'.$m.'月'.$d.'日';//阳历
            $arr[$key]['yinli']=$zyinli[0].'年'.$zyinli[1].$zyinli[2];//阴历


            $dataTime=date('Y').'-'.$m.'-'.$d." {$hour}:00";
            $timeNum=strtotime($dataTime);
            if($timeNum<strtotime(date('Ymd'))){//小于今天
                $nextYear=1;
                $dataTime=(date('Y')+1).'-'.$m.'-'.$d." {$hour}:00";
                $timeNum=strtotime($dataTime);
            }else{
                $nextYear=0;
            }
            $arr[$key]['kindName']=$kindListArr[$value['kind']-1]['name'];
            $arr[$key]['time']=$timeNum;$sortNumArr[$timeNum]=1;
            $dateZ=date('z',$timeNum);
            $dateZthisY=date('z',time());
            if($nextYear){//明年
                $thisYearDay=$this->thisYearDay(date('Y'));
                $dateGap=$thisYearDay-$dateZthisY+$dateZ;
            }else{
                $dateGap=$dateZ-$dateZthisY;
            }

            $arr[$key]['dateGap']=$dateGap;

            if($m==date('m')&&$d==date('d')){//今天
                $arr[$key]['sortType']=1;
            }elseif($m==date('m')&&$d>date('d')){//本月
                $arr[$key]['sortType']=2;
            }
            $sortNumM=date('m')+1;$sortNumM>12?$sortNumM=1:$sortNumM;
            if($m==$sortNumM){//下个月
                $arr[$key]['sortType']=3;
            }
        }

        ksort($sortNumArr);
        $ArrData=array(
            'data1'=>array('name'=>'今日','content'=>''),
            'data2'=>array('name'=>'本月','content'=>''),
            'data3'=>array('name'=>'下个月','content'=>''),
            'data4'=>array('name'=>'其他','content'=>''),
        );
        $sortArrData1=array();$sortArrData2=array();$sortArrData3=array();$sortArrData4=array();
        foreach($sortNumArr as $key=>$value){
            foreach($arr as $k=>$v){
                if($key==$v['time']){
                    if($v['sortType']==1){
                        array_push($sortArrData1,$arr[$k]);
                    }elseif($v['sortType']==2){
                        array_push($sortArrData2,$arr[$k]);
                    }elseif($v['sortType']==3){
                        array_push($sortArrData3,$arr[$k]);
                    }else{
                        array_push($sortArrData4,$arr[$k]);
                    }
                }
            }
        }
        $ArrData['data1']['content']=$sortArrData1;
        $ArrData['data2']['content']=$sortArrData2;
        $ArrData['data3']['content']=$sortArrData3;
        $ArrData['data4']['content']=$sortArrData4;
        //dump($ArrData);
        echo json_encode($ArrData,JSON_UNESCAPED_UNICODE);
    }
    public function thisYearDay($year){//年份天数
        $days=date('z',strtotime($year.'-12-31 01:00'));
        $days+=1;
        return $days;
    }
    public function sunTime($longitude=null,$time=null,$type=null){//真太阳时
        if($longitude){

        }else{
            $time=$_REQUEST['time'];
            $longitude=$_REQUEST['longitude'];//经度
        }
        judgeData(array($time,$longitude),$_REQUEST);
        $Mingpan=new \Library\Mingpan();
        $date=$Mingpan->trueSunTime($time,$longitude);
        $arr=array(
            'code'=>1,
            'time'=>$date
        );
        if($type==1){return $date;}
        echo json_encode($arr);
    }
    public function getLongitude($address=null,$type=null){//获取经度
        if(empty($address)){
            $address=$_REQUEST['address'];
        }
        //judgeData(array($address),$_REQUEST);
        $address=str_replace(' ','',$address);
        
        $longitude=S("longitude".$address);
        if(empty($longitude)){
            $url="http://api.map.baidu.com/geocoding/v3/?address={$address}&output=json&ak=7YMmGpxQqLKuV2IrUH6yH6x0fEsbY0QS";
            $json=curlGet($url);
            $jsonArr=json_decode($json,true);
            $longitude=round($jsonArr['result']['location']['lng'],2);
            S("longitude".$address,$longitude,360000);
        }

        $arr=array(
            'code'=>1,
            'longitude'=>$longitude,
        );
        if($type==1){
            return $longitude;
        }
        echo json_encode($arr);
    }
    public function ZWmingpan(){//紫微命盘
        $sid=$_REQUEST['sid'];
        $orderid=$_REQUEST['orderid'];
        $Gz=$_REQUEST['gz'];//干支
        $dx=$_REQUEST['dx'];//大限
        $ln=$_REQUEST['ln'];//流年年份
        //judgeData(array($sid),$_REQUEST);

        if($sid){
            if(S('mingpan'.$sid)){
                $userData=S('mingpan'.$sid);
            }else{
                $userData=M()->query("select username,birthday,sex,addr,star,longitude,lnymd,sid,uid from data_app_tool_user where sid='{$sid}'");
                S('mingpan'.$sid,$userData,30);
            }
            $status=-1;
        }else if($orderid){
            $userData=M()->query("select status,username,birthday,sex,addr,lnymd,sid,uid from data_app_tool_order where ordernum='{$orderid}'");
            $status=$userData[0]['status'];
        }

        $birthday=$userData[0]['birthday'];
        $sex=$userData[0]['sex'];
        $star='留空';

        $addr=str_replace(' ','',$userData[0]['addr']);
        $longitude=$this->getLongitude($addr,1);

        $lnymd=$userData[0]['lnymd'];

        $ymdArr=explode('-',$birthday);
        $str0=$ymdArr[0];
        if($str0>10){
            $day=substr($ymdArr[2],0,2);
            $hour=substr($ymdArr[2],3,2);
            $birthday="0-{$ymdArr[0]}-{$ymdArr[1]}-{$day}-".intval($hour);
        }

        $Mingpan=new \Library\Mingpan();
        if($Gz){
            $lnDxDataArr=$Mingpan->lnDxGzChange($Gz);
        }
        $arr=$Mingpan->ziweidoushu($birthday,$sex,$star,$sid,$longitude,$lnymd,$lnDxDataArr,$dx,$ln,$Gz);

        //大运十二宫
        //$arrDayunSrg=$MingpanLn->dayunSeg($arr['dayun']['gz'][0]);

        $arr['username']=$userData[0]['username'];
        $arr['birthday']=$userData[0]['birthday'];
        $arr['addr']=$userData[0]['addr'];
        $arr['sid']=$userData[0]['sid'];
        $arr['uid']=$userData[0]['uid'];
        $arr['status']=$status;

        //dump($arr);exit;
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function ZWanalysis(){//紫微命盘解析
//        $sid=$_REQUEST['sid'];
//        $orderid=$_REQUEST['orderid'];
//        $typeName=$_REQUEST['typeName'];//宫位名称
//        judgeData(array($typeName),$_REQUEST);
//        if($sid){
//            if(S('mingpan'.$sid)){
//                $userData=S('mingpan'.$sid);
//            }else{
//                $userData=M()->query("select birthday,sex from data_app_tool_user where sid='{$sid}'");
//                S('mingpan'.$sid,$userData,6800);
//            }
//        }
//        if($orderid){
//            $userData=M()->query("select birthday,sex from data_app_tool_order where ordernum='{$orderid}'");
//        }
//        $birthday=$userData[0]['birthday'];
//        $sex=$userData[0]['sex'];
//        $Mingpan=new \Library\Mingpan();
//        $arr=$Mingpan->ZWanalysis($birthday,$sex,$typeName);
        //dump($arr);exit;

        //echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }

    public function BZmingpan($Tbirthday=null,$Tsex=null){//八字命盘
        if(empty($Tbirthday)){
            $sid=$_REQUEST['sid'];
            $orderid=$_REQUEST['orderid'];
            //judgeData(array($sid),$_REQUEST);
            if($sid){
                if(S('mingpan'.$sid)){
                    $userData=S('mingpan'.$sid);
                }else{
                    $userData=M()->query("select username,birthday,sex,star,longitude,addr,longitude from data_app_tool_user where sid='{$sid}'");
                    S('mingpan'.$sid,$userData,10);
                }
            }
            if($orderid){
                $userData=M()->query("select username,birthday,sex,addr,sid from data_app_tool_order where ordernum='{$orderid}'");
            }
            $birthday=$userData[0]['birthday'];
            $sex=$userData[0]['sex'];
            $addr=str_replace(' ','',$userData[0]['addr']);
            $longitude=$this->getLongitude($addr,1);
        }else{
            $birthday=$Tbirthday;
            $sex=$Tsex;
        }

        $Mingpan=new \Library\Mingpan();
        $arr=$Mingpan->bazipaipan($birthday,$sex,$longitude);
        if($Tbirthday){
            return $arr;
        }
        $arr['username']=$userData[0]['username'];
        $arr['birthday']=$birthday;
        $arr['addr']=$userData[0]['addr'];
        $arr['sid']=$userData[0]['sid'];

        //$ymdArr=explode('-',$birthday);
        //$sunTime=$this->sunTime($longitude,"{$ymdArr[1]}-{$ymdArr[2]}-{$ymdArr[3]} {$ymdArr[4]}:{$ymdArr[5]}",1);
        //$arr['birthday']=$sunTime;

        //dump($arr);
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function BZresult(){//八字排盘结果
        $sid=$_REQUEST['sid'];
        $orderid=$_REQUEST['orderid'];
        //judgeData(array($sid),$_REQUEST);
        if($sid){
            if(S('mingpan'.$sid)){
                $userData=S('mingpan'.$sid);
            }else{
                $userData=M()->query("select username,birthday,sex,star,longitude,addr from data_app_tool_user where sid='{$sid}'");
                S('mingpan'.$sid,$userData,10);
            }
            $status=-1;
        }
        if($orderid){
            $userData=M()->query("select username,birthday,sex,addr,status,sid from data_app_tool_order where ordernum='{$orderid}'");
            $status=$userData[0]['status'];
        }
        $birthday=$userData[0]['birthday'];$sex=$userData[0]['sex'];
        $Mingpan=new \Library\Mingpan();
        $arr=$Mingpan->bzRusult($birthday,$sex);
        $arr['status']=$status;
        $arr['sid']=$userData[0]['sid'];
        //dump($arr);
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }

    public function liuyaoIndex(){//六爻
        $uid=$_REQUEST['uid'];
        $title=$_REQUEST['title'];
        $sid=$_REQUEST['sid'];
        $cjTime=$_REQUEST['zyTime'];
        $sumType=$_REQUEST['sumType'];//求和
        $addTime=$_REQUEST['addTime'];//动爻加时间
        //1少阳  2少阴  3老阳  4老阴
        $x1=$_REQUEST['x1'];$x2=$_REQUEST['x2'];$x3=$_REQUEST['x3'];
        $s1=$_REQUEST['s1'];$s2=$_REQUEST['s2'];$s3=$_REQUEST['s3'];
        $guaxiang=array('',$x1,$x2,$x3,$s1,$s2,$s3);
        $type=$_REQUEST['type'];//1.在线起卦2.手工指定3.电脑自动4.时间起卦5.单数起卦6.双数起卦7.汉字起卦8.挂名起卦9.摇动起卦
        $qgTime=$_REQUEST['time'];//起卦时间
        $qgNumber1=$_REQUEST['number1'];//数字起卦
        $qgNumber2=$_REQUEST['number2'];//双数起卦
        $qgStr=$_REQUEST['string'];//汉字起卦
        $guaName1=$_REQUEST['guaName1'];
        $guaName2=$_REQUEST['guaName2'];
        if(empty($qgTime)){
            $qgTime='0-'.date('Y-m-d-H-i');
        }
        if($uid){
            judgeData(array($title),$_REQUEST);
            if($x1){
                $jsonData=json_encode($guaxiang);
            }
            M()->query("insert into data_app_tool_lypp (uid,title,time,type,guaxiang,string,number1,number2,guaName1,guaName2,cjTime,sumType,addTime)values('{$uid}','{$title}','{$qgTime}','{$type}','{$jsonData}','{$qgStr}','{$qgNumber1}','{$qgNumber2}','{$guaName1}','{$guaName2}','{$cjTime}','{$sumType}','{$addTime}')");
            $sid=mysql_insert_id();
            $this->orderPay($sid,3,$uid,1,2);//生成订单
        }else if($sid){
            $arr=M()->query("select * from data_app_tool_lypp where sid='{$sid}'");
            $sumType=$arr[0]['sumType'];;//求和
            $addTime=$arr[0]['addTime'];;//动爻加时间
            $cjTime=$arr[0]['cjTime'];
            $title=$arr[0]['title'];
            $type= $arr[0]['type'];
            $qgTime=$arr[0]['time'];
            $qgStr=$arr[0]['string'];
            $guaxiang=json_decode($arr[0]['guaxiang'],true);
            $qgNumber1=$arr[0]['number1'];//数字起卦
            $qgNumber2=$arr[0]['number2'];//双数起卦
            $guaName1=$arr[0]['guaName1'];
            $guaName2=$arr[0]['guaName2'];
        }else{
            echo '缺少参数';exit;
        }

        if($cjTime){
            $ymdArr=explode('-',$cjTime);
        }else{
            $ymdArr=explode('-',$qgTime);
        }
        $y=$ymdArr[1];$m=$ymdArr[2];$d=$ymdArr[3];$hour=$ymdArr[4];$min=$ymdArr[5];
        $ymd=$y.'-'.$m.'-'.$d;

        zwmp($ymd,$hour,'男',cookie('datatype'));
        $sizhu=I('globals.sizhu');
        $rikong=I('globals.rikong');//日空/旬空/空亡

        $classZyqg=new \Library\Zhouyiqigua();

        if($type==4){
            $guaxiang=zhouyiqigua_year($y.'-'.$m.'-'.$d,$hour,$min);
        }else if($type==5||$type==6){
            $guaxiang=zhouyiqigua_number($type,$qgNumber1,$hour,$qgNumber2,$sumType,$addTime);
        }else if($type==7){
            $Trans = new \Library\Trans();
            $fStr=$Trans->c2t($qgStr);//转繁体
            $bihua=$this->xingmingZft($fStr);//获取笔画
            $number='';
            foreach($bihua as $key=>$value){$number+=$value;}
            $guaxiang=zhouyiqigua_number(5,$number,$hour);
        }else if($type==8){
            $zyqgData=$classZyqg->zyqgInterface(0,$sizhu,$guaName1,$guaName2);
        }

        if(empty($guaName1)){
            $zyqgData=$classZyqg->zyqgInterface($guaxiang,$sizhu);
        }

        if($uid){
            $Arr=array('sid'=>$sid,);
            echo json_encode($Arr);exit;
        }

        $typeArr=array(1=>'在线起卦', 2=>'手工指定', 3=>'电脑自动', 4=>'时间起卦', 5=>'单数起卦', 6=>'双数起卦', 7=>'汉字起卦', 8=>'挂名起卦', 9=>'摇动起卦',);
        $zyqgData['sizhu']=$sizhu;
        $zyqgData['xunkong']=$rikong;
        $zyqgData['title']=$title;
        $zyqgData['time']=$qgTime;
        $zyqgData['type']=$type;
        $zyqgData['typeName']=$typeArr[$type];
        $zyqgData['zyTime']=$cjTime;

        //神煞
        $sehnshaData=$this->shensha($sizhu);
        $zyqgData['shensha']=$sehnshaData;
        $zyqgDataBF=$zyqgData;

        $zyqgData=$this->zyqgDataDaoshu($zyqgData,$zyqgDataBF);//颠倒处理
        if($zyqgData['bguaxiang'][1]==''){//空变卦隐藏
            $zyqgData['bguaxiang']='';
            $zyqgData['arrbiangua']='';
        }
        $zyqgData=array_filter($zyqgData);
        $zyqgData['productId']='smgold50';
        if($qgTime){
            $zyqgData['code']=1;
        }else{
            $zyqgData['code']=0;
        }
        //dump($zyqgData);
        echo json_encode($zyqgData,JSON_UNESCAPED_UNICODE);
    }
    public function Qizhengsiyu(){//七政四余
        $sid=$_REQUEST['sid'];
        $orderid=$_REQUEST['orderid'];
        $lnYear=$_REQUEST['lnYear'];
        //judgeData(array($sid),$_REQUEST);
        if($sid){
            if(S('mingpan'.$sid)){
                $userData=S('mingpan'.$sid);
            }else{
                $userData=M()->query("select username,birthday,sex,addr,lnymd,longitude from data_app_tool_user where sid='{$sid}'");
                S('mingpan'.$sid,$userData,10);
            }
            $status=-1;
        }
        if($orderid){
            $userData=M()->query("select username,birthday,sex,addr,status,sid,longitude from data_app_tool_order where ordernum='{$orderid}'");
            $status=$userData[0]['status'];
        }
        $birthday=$userData[0]['birthday'];$sex=$userData[0]['sex'];$lnYmd=$userData[0]['lnymd'];
        //$longitude=$userData[0]['longitude'];

        $addr=str_replace(' ','',$userData[0]['addr']);
        $longitude=$this->getLongitude($addr,1);

        $qizhengsiyu=new \Library\Qizhengsiyu();
        if($lnYear){$lnYmd=$lnYear.substr($lnYmd,4,10);}

        $Arr=$qizhengsiyu->index($birthday,$sex,$lnYmd,$longitude);
        $data=$qizhengsiyu->DataTotal($Arr['sizhu'],$Arr['gongwei']);
        $dataPay=$qizhengsiyu->DataTotalPay($Arr['stars'],$Arr['gongwei'],$userData[0]['birthday'],$Arr['shensha'],$Arr['liming']);

        $Arr['data']=$data;
        $Arr['status']=$status;
        $Arr['username']=$userData[0]['username'];
        $Arr['birthday']=$userData[0]['birthday'];
        $Arr['sid']=$userData[0]['sid'];
        $Arr['addr']=$userData[0]['addr'];
        $Arr['sex']=$userData[0]['sex'];
        $Arr['dataPay']=$dataPay;
        //dump($Arr);
//        exit;

        echo json_encode($Arr,JSON_UNESCAPED_UNICODE);
    }
    public function Qimendunjia(){//奇门遁甲排盘
        $sid=$_REQUEST['sid'];
        if($sid){
            if(S('mingpan'.$sid)){
                $userData=S('mingpan'.$sid);
            }else{
                $userData=M()->query("select username,birthday,sex,addr,lnymd,remarks from data_app_tool_user where sid='{$sid}'");
                S('mingpan'.$sid,$userData,30);
            }
            $status=-1;
        }
        $birthday=$userData[0]['birthday'];
        $remarks=$userData[0]['remarks'];
        $qimendunjia=new \Library\Qimendunjia();
        $Arr=$qimendunjia->index($birthday,$remarks);
        //dump($Arr);
        echo json_encode($Arr,JSON_UNESCAPED_UNICODE);
    }
    public function LiurenPaipan(){//大六壬排盘
        $sid=$_REQUEST['sid'];
        if($sid){
            if(S('mingpan'.$sid)){
                $userData=S('mingpan'.$sid);
            }else{
                $userData=M()->query("select username,birthday,sex,addr,lnymd,remarks from data_app_tool_user where sid='{$sid}'");
                S('mingpan'.$sid,$userData,30);
            }
            $status=-1;
        }
        $birthday=$userData[0]['birthday'];
        $remarks=$userData[0]['remarks'];
        $sex=$userData[0]['sex'];
        $username=$userData[0]['username'];
        $liuren=new \Library\DaLiuren();
        $Arr=$liuren->index($birthday,$remarks,$sex,$username);
        //dump($Arr);
       echo json_encode($Arr,JSON_UNESCAPED_UNICODE);
    }
    public function tbssCs(){//铁板神数
        $sid=$_REQUEST['sid'];
        if($sid){
            if(S('mingpan'.$sid)){
                $userData=S('mingpan'.$sid);
            }else{
                $userData=M()->query("select username,birthday,sex,addr,lnymd,remarks from data_app_tool_user where sid='{$sid}'");
                S('mingpan'.$sid,$userData,30);
            }
            $birthday=$userData[0]['birthday'];
            $sexNum=$userData[0]['sex'];
            $remarksArr=json_decode($userData[0]['remarks'],true);
            $type=$remarksArr['tbType'];
            $twNum1=$remarksArr['twNum1'];
            $twNum2=$remarksArr['twNum2'];
        }else{
            $birthday=$_REQUEST['birthday'];//
            $type=$_REQUEST['type'];//1.八卦加则取数法   2.元会运世    2.1 获取条文符合情况 第一条  2.2第二条
            $twNum1=$_REQUEST['twNum1'];
            $twNum2=$_REQUEST['twNum2'];
        }

        judgeData(array($birthday),$_REQUEST);
        $ymdArr=explode('-',$birthday);
        $y=$ymdArr[1];$m=$ymdArr[2];$d=$ymdArr[3];
        if($y<1900){
            $y=$ymdArr[0];$m=$ymdArr[1];$d=$ymdArr[2];
            $ymd="{$y}-{$m}-{$d}";$hour=$ymdArr[3];
        }else{
            $ymd="{$ymdArr[1]}-{$ymdArr[2]}-{$ymdArr[3]}";$hour=$ymdArr[4];
        }

        zwmp($ymd,$hour,'男','dy');
        $sizhu=I('globals.sizhu');
        $yysex=I('globals.yysex');
        $dayungz=I('globals.dayungz');//大运干支

        cookie('yysex',$yysex);
        cookie('ymd',$ymd);

        if($sid){
            $zyinli=yinli($y,$m,$d);
            $zyangli=$y.'年'.$m.'月'.$d.'日'.' '.$hour.'时';//阳历
            $zyinli=$zyinli[0].'年'.$zyinli[1].$zyinli[2]." ".mb_substr($sizhu[3],1,1,'utf-8')."时";//阴历
            if($sexNum==1){
                $sex='男';
            }else{
                $sex='女';
            }
            $userData=array(
                'username'=>$userData[0]['username'],
                'addr'=>$userData[0]['addr'],
                'sex'=>$sex,
                'yangli'=>$zyangli,
                'yinli'=>$zyinli,
                'tgType'=>$type,
            );
        }

        $ZhouyiqiguaClass=new \Library\Zhouyiqigua();
        //$Arr=$ZhouyiqiguaClass->tbssBgData($sizhu,$yysex);//八卦取数 暂时不用


        if($type==1){
            $Arr=$ZhouyiqiguaClass->tbssBs2Data($sizhu);//八卦加则取数法
        }elseif($type==3){
            $Arr=$ZhouyiqiguaClass->tbssLndyData($sizhu,$ymd,$hour);//流年大运取数
        }else{
            if($twNum1=="null")$twNum1='';
            if($twNum2=="null")$twNum2='';
            $Arr=$ArrYhys=$ZhouyiqiguaClass->tbssYhysData($sizhu,$type,$twNum1,$twNum2);//元会运世
        }

        //徐氏铁板 数据获取
        $ZhouyiqiguaClass->xsTbss($sizhu,$dayungz,$sexNum);


        $ArrData['sizhu']=$sizhu;
        $ArrData['userData']=$userData;
        $ArrData['data']=$Arr;

        if($type>2&&($twNum1||$twNum2)){
            $time=time();
            $textArr=$_REQUEST;
            $textArr['data']=$ArrData;
            //file_put_contents("./Upload/{$type}tbss{$time}.txt",json_encode($textArr,JSON_UNESCAPED_UNICODE));
        }
        echo json_encode($ArrData,JSON_UNESCAPED_UNICODE);
    }

    public function liuyaoSelect(){//查询用户列表
        $uid=$_REQUEST['uid'];
        judgeData(array($uid),$_REQUEST);
        $arr=M()->query("select sid,title,time,start from data_app_tool_lypp where uid='{$uid}' order by sid limit 15");
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function shensha($sizhu){//四柱神煞获取
        $tgArr=array('甲'=>0, '乙'=>1, '丙'=>2, '丁'=>3, '戊'=>4, '己'=>5, '庚'=>6, '辛'=>7, '壬'=>8, '癸'=>9,);
        $dzArr=array('子'=>0, '丑'=>1, '寅'=>2, '卯'=>3, '辰'=>4, '巳'=>5, '午'=>6, '未'=>7, '申'=>8, '酉'=>9, '戌'=>10, '亥'=>11,);
        $ng=mb_substr($sizhu[0],0,1,'utf-8');
        $yg=mb_substr($sizhu[1],0,1,'utf-8');
        $rg=mb_substr($sizhu[2],0,1,'utf-8');
        $ngNum=$tgArr[$ng];
        $rgNum=$tgArr[$rg];
        $nz=mb_substr($sizhu[0],1,1,'utf-8');
        $yz=mb_substr($sizhu[1],1,1,'utf-8');
        $rz=mb_substr($sizhu[2],1,1,'utf-8');
        $nzNum=$dzArr[$nz];
        $yzNum=$dzArr[$yz];
        $rzNum=$dzArr[$rz];

        $arrData=array();
        $rzArr=array(
            '驿马'=>array('寅','亥','申','巳','寅','亥','申','巳','寅','亥','申','巳'),
            '桃花'=>array('酉','午','卯','子','酉','午','卯','子','酉','午','卯','子',),
            '华盖'=>array('辰','丑','戌','为','辰','丑','戌','未','辰','丑','戌','未'),
            '劫煞'=>array('巳','寅','亥','申','巳','寅','亥','申','巳','寅','亥','申'),
            '亡神'=>array('亥','申','巳','寅','亥','申','巳','寅','亥','申','巳','寅'),
            '将星'=>array('子','酉','午','卯','子','酉','午','卯','子','酉','午','卯'),
        );
        foreach($rzArr as $key=>$value){
            $data=array('gz'=>$value[$rzNum],'name'=>$key);
            array_push($arrData,$data);
        }
        $rgArr=array(
            '贵人'=>array('丑未','子申','亥酉','亥酉','丑未','子申','丑未','寅','卯巳','卯巳'),
            '天乙'=>array('丑未','子申','亥酉','亥酉','丑未','子申','午寅','午寅','卯巳','卯巳'),
            '太极'=>array('子午','子午','卯酉','卯酉','辰戌丑未','辰戌丑未','寅亥','寅亥','巳申','巳申'),
            '文昌'=>array('巳','午','申','酉','申','酉','亥','子','寅','卯'),
            '金舆'=>array('辰','巳','未','申','未','申','戌','亥','丑','寅'),
            '禄神'=>array('寅','卯','巳','午','巳','午','申','酉','亥','子'),
            '国印'=>array('戌','亥','丑','寅','丑','寅','辰','巳','未','申'),
            '羊刃'=>array('卯','寅','午','巳','午','巳','酉','申','子','亥'),
            '福星'=>array('寅子','卯丑','寅子','亥','申','未','午','巳','辰','卯丑'),
            '沐浴'=>array('子','巳','卯','申','卯','申','午','亥','酉','寅',),
            '干禄'=>array('寅','卯','巳','午','巳','午','申','酉','亥','子',),
            '红艳'=>array('午申','午申','寅','未','辰','辰','戌','酉','子','申',),
        );
        foreach($rgArr as $key=>$value){
            $data=array('gz'=>$value[$rgNum],'name'=>$key);
            array_push($arrData,$data);
        }
        $nzArr=array(
            '六厄'=>array('卯','子','酉','午','卯','子','酉','午','卯','子','酉','午'),
            '孤辰'=>array('寅','寅','巳','巳','巳','申','申','申','亥','亥','亥','寅'),
            '寡宿'=>array('戌','戌','丑','丑','丑','辰','辰','辰','未','未','未','戌'),
            '咸池'=>array('酉','午','卯','子','酉','午','卯','子','酉','午','卯','子'),
            '天罗'=>array('','','','','','','','','','','亥','戌'),
            '地网'=>array('','','','','巳','辰','','','','','',''),
            '灾煞'=>array('午','卯','子','酉','午','卯','子','酉','午','卯','子','酉'),
            '丧门'=>array('寅','卯','辰','巳','午','未','申','酉','戌','亥','子','丑'),
            '吊客'=>array('戌','亥','子','丑','寅','卯','辰','巳','午','未','申','酉'),
            '红鸾'=>array('卯','寅','丑','子','亥','戌','酉','申','未','午','巳','辰',),
            '天喜'=>array('酉','申','未','午','巳','辰','卯','寅','丑','子','辰','巳',),
        );
        foreach($nzArr as $key=>$value){
            if($value[$nzNum]){
                $data=array('gz'=>$value[$nzNum],'name'=>$key);
                array_push($arrData,$data);
            }
        }

        return $arrData;
    }
    public function zyqgDataDaoshu($zyqgData,$zyqgDataBF){//颠倒处理
        $zyqgData['guaxiang'][1]=$zyqgDataBF['guaxiang'][6];$zyqgData['guaxiang'][2]=$zyqgDataBF['guaxiang'][5];$zyqgData['guaxiang'][3]=$zyqgDataBF['guaxiang'][4];$zyqgData['guaxiang'][4]=$zyqgDataBF['guaxiang'][3];$zyqgData['guaxiang'][5]=$zyqgDataBF['guaxiang'][2];$zyqgData['guaxiang'][6]=$zyqgDataBF['guaxiang'][1];
        $zyqgData['arrbengua']['fushen1']=$zyqgDataBF['arrbengua']['fushen6'];$zyqgData['arrbengua']['fushen2']=$zyqgDataBF['arrbengua']['fushen5'];$zyqgData['arrbengua']['fushen3']=$zyqgDataBF['arrbengua']['fushen4'];$zyqgData['arrbengua']['fushen4']=$zyqgDataBF['arrbengua']['fushen3'];$zyqgData['arrbengua']['fushen5']=$zyqgDataBF['arrbengua']['fushen2'];$zyqgData['arrbengua']['fushen6']=$zyqgDataBF['arrbengua']['fushen1'];
        $zyqgData['bguaxiang'][1]=$zyqgDataBF['bguaxiang'][6];$zyqgData['bguaxiang'][2]=$zyqgDataBF['bguaxiang'][5];$zyqgData['bguaxiang'][3]=$zyqgDataBF['bguaxiang'][4];$zyqgData['bguaxiang'][4]=$zyqgDataBF['bguaxiang'][3];$zyqgData['bguaxiang'][5]=$zyqgDataBF['bguaxiang'][2];$zyqgData['bguaxiang'][6]=$zyqgDataBF['bguaxiang'][1];
        $zyqgData['arrbiangua']['fushen1']=$zyqgDataBF['arrbiangua']['fushen6'];$zyqgData['arrbiangua']['fushen2']=$zyqgDataBF['arrbiangua']['fushen5'];$zyqgData['arrbiangua']['fushen3']=$zyqgDataBF['arrbiangua']['fushen4'];$zyqgData['arrbiangua']['fushen4']=$zyqgDataBF['arrbiangua']['fushen3'];$zyqgData['arrbiangua']['fushen5']=$zyqgDataBF['arrbiangua']['fushen2'];$zyqgData['arrbiangua']['fushen6']=$zyqgDataBF['arrbiangua']['fushen1'];
        $zyqgData['arrliushou'][0]=$zyqgDataBF['arrliushou'][5];$zyqgData['arrliushou'][1]=$zyqgDataBF['arrliushou'][4];$zyqgData['arrliushou'][2]=$zyqgDataBF['arrliushou'][3];$zyqgData['arrliushou'][3]=$zyqgDataBF['arrliushou'][2];$zyqgData['arrliushou'][4]=$zyqgDataBF['arrliushou'][1];$zyqgData['arrliushou'][5]=$zyqgDataBF['arrliushou'][0];
        return $zyqgData;
    }
    public function xingmingZft($ming){//转笔画
        $mingLeng=strlen($ming)/3;
        $Mbihua=cookie('Mbihua'.$ming);
        if(empty($Mbihua)){
            $Mbihua=array();
            for($i=0;$i<$mingLeng;$i++){
                $word=mb_substr($ming,$i,1,'utf-8');
                $url = "https://bihua.911cha.com/?q={$word}";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);//设置请求地址
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//不需要证书验证
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//不需要主机验证
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//不直接输出到页面
                $json = curl_exec($ch);

                preg_match("/class=\"bihua\"[\s\S]*画<\/span>/",$json,$matches);
                preg_match("/>[\s\S]*画/",$matches[0],$bihua);
                $Mbihua[$i]=intval(mb_substr($bihua[0],1,2));
                if($word=='茁'){
                    $Mbihua[$i]=11;
                }
            }
        }
        cookie('Mbihua'.$ming,$Mbihua);
        return $Mbihua;
        curl_close($ch);
    }

    public function orderPay($sid=null,$type=null,$uid=null,$returnType=null,$interface=null){//订单支付
        if($interface){//接口调用
        }else{
            $uid=$_REQUEST['uid'];
            $sid=$_REQUEST['sid'];
            $type=$_REQUEST['type'];//1紫微命盘  2八字命盘  3六爻  4七政四余 5奇门遁甲
            $returnUrl=$_REQUEST['returnUrl'];//返回地址
            $returnJson=json_decode($returnUrl,true);
            $returnUrl=$returnJson['url'];
            $returnType=$_REQUEST['returnType'];//是否返回订单号
        }

        judgeData(array($sid,$type,$uid),$_REQUEST);
        if(!is_numeric($sid)){
            echo "sid错误:{$sid}";
            dump($_REQUEST);
            exit;
        }

//        $time=time();
//        $strData=json_encode($_REQUEST,JSON_UNESCAPED_UNICODE);
//        file_put_contents("./Upload/AppToolOrderPayData{$time}.txt",$strData);

        $price=28;
        if($uid=='454103638'||$uid=='454429974'||$_REQUEST['channel']=='qudao100'){
            $price='0.01';
        }

        $AppToolOrderid=S('AppToolOrderid'.$sid.$type);
        if($AppToolOrderid){
            $orderid=$AppToolOrderid;
        }else{
            $orderid='LQAPP'.$type.date('Ymd').mt_rand(1000,9999).date('His').'S'.$sid;
            S('AppToolOrderid'.$sid.$type,$orderid,300);
            $orderData=M()->query("select id,birthday from data_app_tool_order where sid='{$sid}' and uid='{$uid}' and type='{$type}' order by id desc");
            $userArr=M()->query("select birthday,sex,username,addr,lnymd from data_app_tool_user where sid='{$sid}'");
            foreach($orderData as $key=>$value){//订单过滤
                if($value['birthday']==$userArr[0]['birthday']){
                    $userEqOrder=1;
                    $Oid=$value['id'];break;
                }
            }

            if(empty($orderData[0]['id'])||$userEqOrder!=1){
                if($type==3){//六爻
                    $userArr=M()->query("select cjTime,title,guaxiang from data_app_tool_lypp where sid='{$sid}'");
                    $username=$userArr[0]['title'];
                    $birthday=$userArr[0]['cjTime'];$sex=0;
                }else{
                    $username=$userArr[0]['username'];$addr=$userArr[0]['addr'];$lnymd=$userArr[0]['lnymd'];
                    $birthday=$userArr[0]['birthday'];$sex=$userArr[0]['sex'];$longitude=$userArr[0]['longitude'];
                }

                M()->query("insert into data_app_tool_order (ordernum,price,type,uid,sid,birthday,sex,username,addr,lnymd,longitude)values('{$orderid}','{$price}','{$type}','{$uid}','{$sid}','{$birthday}','{$sex}','{$username}','{$addr}','{$lnymd}','{$longitude}')");
            }else{
                M()->query("update data_app_tool_order set ordernum='{$orderid}' where id='{$Oid}'");
            }
        }


        if($returnType==1){//返回订单号
            if($interface){//提交接口调用
                return $returnType;
            }else{
                $Arr=array(
                    'code'=>1,
                    'content'=>$orderid,
                );
                echo json_encode($Arr);exit;
            }
        }

//        if(substr_count($returnUrl,'?')){
//            $returnUrl.="&orderid={$orderid}";
//        }else{
            $returnUrl.="?orderid={$orderid}&sid={$sid}";
        //}
        $data=array(
            'orderid'=>$orderid,
            'price'=>$price,
            'ordername'=>'灵棋排盘',
            'returnUrl'=>$returnUrl,
            'notifyUrl'=>'https://hy.yixueqm.com/zhiming/index.php/Home-InterfaceAppTool-notifyUrl',
        );

        $dataJson=json_encode($data,JSON_UNESCAPED_UNICODE);

        echo "<form id='form' action='https://hy.yixueqm.com/interface/index.php/Home/Index/interfacePublicOrder' method='POST'>
               <input type='hidden'  name='data' value='{$dataJson}'>
            </form>
            <script type='text/javascript'>document.getElementById('form').submit()</script>"
        ;

//        $jumpUrl="https://hy.yixueqm.com/interface/index.php/Home/Index/interfacePublicOrder?data={$dataJson}";
//        header("location:".$jumpUrl);
    }
    public function selectOrderidPay(){//查询订单是否支付
        $orderid=$_REQUEST['orderid'];
        $sid=$_REQUEST['sid'];
        $type=$_REQUEST['type'];
//        judgeData(array($orderid),$_REQUEST);
        if($orderid){
            $orderData=M()->query("select id,status from data_app_tool_order where ordernum='{$orderid}'");
            $arr=array('status'=>$orderData[0]['status']);
        }elseif($sid){
            $userArr=M()->query("select username,birthday,sex,addr,type from data_app_tool_user where sid='{$sid}'");
            //dump($userArr);
            $birthday=$userArr[0]['birthday'];
            $username=$userArr[0]['username'];
            $sex=$userArr[0]['sex'];
            $addr=$userArr[0]['addr'];
            if(empty($type)){
                $type=$userArr[0]['type'];
            }
            $orderData=M()->query("select id,status from data_app_tool_order where sid='{$sid}' and type='{$type}' and birthday='{$birthday}' and sex='{$sex}' and addr='{$addr}' and username='{$username}'");
            //dump($orderData);
            $arr=array('status'=>$orderData[0]['status']);
        }

        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
    public function selectOrderid(){//查询订单
        $uid=$_REQUEST['uid'];
        $type=$_REQUEST['type'];
        judgeData(array($uid,$type),$_REQUEST);
        $typeJgUrl=array(
            1=>'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/zwds/index',
//            2=>'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/bzfx/fenxi',
            4=>'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/qzsy/index',
            5=>'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/qmdj/index',
            7=>"http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/dlr/index",
            8=>'http://web.ddznzj.com/lingqiyixue/tbss/#/pages/tbss/result',
        );
        if($type>=7||$type==5){//铁板神数
            $orderData=M()->query("select sid,type,username,birthday,sex,createtime,addr,information,kind,remarks,type from data_app_tool_user where uid='{$uid}' and del<2 and type='{$type}' order by sid desc limit 20");
        }else{
            $orderData=M()->query("select id,ordernum,type,status,paykind,sid,username,birthday,sex,createtime from data_app_tool_order where uid='{$uid}' and type='{$type}' order by id desc limit 20");
        }
        foreach($orderData as $key=>$value){
            if($typeJgUrl[$value['type']]){
                $path=$typeJgUrl[$value['type']]."?sid={$value['sid']}";
                if($value['status']==1){
                    $path.="&orderid={$value['ordernum']}";
                }
                $orderData[$key]['path']=$path;
            }
            if($value['type']==5){
                $arrUser=M()->query("select remarks from data_app_tool_user where sid='{$value['sid']}'");
                $arrRemarks=json_decode($arrUser[0]['remarks'],true);
                $username='';
                if($arrRemarks['qijuType']==1){$username.='四柱起局';}else{$username.='公历起局';}
                if($arrRemarks['qimen']==1){$username.='-飞盘奇门';}else{$username.='-转盘奇门';}
                if($arrRemarks['runfa']==1){$username.='-拆补无闰法';}else{$username.='-超接置闰法';}
                $orderData[$key]['username']=$username;
                $orderData[$key]['sizhu']=$arrRemarks['sizhu'];
                $orderData[$key]['jushu']=$arrRemarks['jushu'];
            }elseif($value['type']==8){
                $arrRemarks=json_decode($value['remarks'],true);
                if($arrRemarks['tbType']==1){$typeName="八卦加则法";
                }elseif($arrRemarks['tbType']==2){$typeName="元会运世法";
                }elseif($arrRemarks['tbType']==3){$typeName="流年大运法";
                }
                $orderData[$key]['typeName']=$typeName;
            }elseif($value['type']==7){
                $arrRemarks=json_decode($value['remarks'],true);
                $orderData[$key]['qikeTime']=$arrRemarks['qikeTime'];
                if($arrRemarks['qijuType']==1){$qijuName="正时起局";
                }else{$qijuName="报数起局";
                }
                $orderData[$key]['qijuName']=$qijuName;
                $orderData[$key]['typeName']="六壬排盘";
            }
        }
        $result=array('code'=>1,'content'=>$orderData,'tip'=>"success");
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }
    public function notifyUrl(){//异步回调
        $xmldata=file_get_contents("php://input");//接收到xml数据

        if($_REQUEST['orderid']){
            $ordernum=$_REQUEST['orderid'];
            $paykind=3;//第三方
        }else if($_REQUEST['out_trade_no']){//支付宝
            $ordernum=$_REQUEST['out_trade_no'];
            $transactionId=$_REQUEST['trade_no'];
            if($_REQUEST['app_id']=='2016101302144443'&&$_REQUEST['trade_status']=='TRADE_SUCCESS'){//过虑
            }else{
                echo 'false';exit;
            }
            $paykind=1;
        }else if($xmldata){
            $paykind=0;
            $valuesArr = json_decode(json_encode(simplexml_load_string($xmldata, 'SimpleXMLElement', LIBXML_NOCDATA)), true);//把xml字符串解析成数组
            $ordernum=$valuesArr['out_trade_no'];
            $transactionId=$valuesArr['transaction_id'];
        }
        if($ordernum){
            M()->query("update data_app_tool_order set status=1,paykind='{$paykind}',transactionId='{$transactionId}' where ordernum='{$ordernum}'");
        }
    }

    public function wln_mycesuan(){//万年历 我的测算
        indexRvent();//测算首页执行事件
        if(I('request.uid')){
            $uid=I('request.uid');
            cookie('uid',$uid);
        }else{
            $uid=cookie('uid');
        }

        $orderData=M()->query("select id,username,ordernum orderid,type,status,sid from data_app_tool_order where uid='{$uid}' and (type=1 or type=4) order by id desc limit 20");
        $typeJgUrl=array(
            1=>array('name'=>'紫微斗数', 'url'=>'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/zwds/index?packname=com.mrkj.calendar&orderid=',),
            4=>array('name'=>'七政四余', 'url'=> 'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/qzsy/index?packname=com.mrkj.calendar&orderid=',),
        );
        $arr1=array();$arr2=array();
        foreach($orderData as $key=>$value){
            $sid=$value['sid'];
            $orderData[$key]['name']=$typeJgUrl[$value['type']]['name'];
            $orderData[$key]['url']=$typeJgUrl[$value['type']]['url'].$value['orderid']."&sid={$sid}";
            if($value['status']==1){
                array_push($arr1,$orderData[$key]);
            }else{
                array_push($arr2,$orderData[$key]);
            }
        }
        $arr=array_merge($arr1,$arr2);

        $this->assign('arr',$arr);
        $this->display("Index/ZM_mycesuan_wnl");
    }
    public function wln_select(){//万年历 查询
        $orderid=I('request.keyword');
        $orderData=M()->query("select id,username,ordernum orderid,type,status,sid from data_app_tool_order where ordernum='{$orderid}'");
        if($_REQUEST['number']==1){//ajax回调
            if(empty($orderData[0])){
                echo '1';
            }else{echo '2';}
            exit;
        }
        $typeJgUrl=array(
            1=>array('name'=>'紫微斗数', 'url'=>'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/zwds/index?packname=com.mrkj.calendar&orderid=',),
            4=>array('name'=>'七政四余', 'url'=> 'http://hy.yixueqm.com/webH5/lingqiyixue/#/pages/qzsy/index?packname=com.mrkj.calendar&orderid=',),
        );
        foreach($orderData as $key=>$value){
            $sid=$value['sid'];
            $orderData[$key]['name']=$typeJgUrl[$value['type']]['name'];
            $orderData[$key]['url']=$typeJgUrl[$value['type']]['url'].$value['orderid']."&sid={$sid}";
        }
        $this->assign('arr',$orderData);
        $this->display("Index/ZM_mycesuan_wnl");
    }

}